package com.menggudf.common.utils;

import okhttp3.OkHttpClient;
import java.util.concurrent.TimeUnit;

public class OkHttpSingleton {
    // 使用 volatile 保证可见性和有序性
    private static volatile OkHttpClient instance;

    // 私有构造方法防止外部实例化
    private OkHttpSingleton() {}

    public static OkHttpClient getInstance() {
        if (instance == null) {
            synchronized (OkHttpSingleton.class) {
                if (instance == null) {
                    instance = createClient();
                }
            }
        }
        return instance;
    }

    private static OkHttpClient createClient() {
        return new OkHttpClient.Builder()
                .connectTimeout(100, TimeUnit.MINUTES)
                .readTimeout(100, TimeUnit.MINUTES)
                // 可添加其他统一配置（如拦截器、SSL配置等）
                .build();
    }
}